/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.uml_generator.model.impl;

import com.genia.toolbox.uml_generator.model.AbstractJavaObject;
import com.genia.toolbox.uml_generator.model.AttributeModel;
import com.genia.toolbox.uml_generator.model.EnumerationModel;

/**
 * this class represent the attributes entities from the xmi file.
 */
public class AttributeModelImpl
    extends AbstractObjectImpl
    implements AttributeModel
{

  /**
   * the type of the attribute.
   */
  private AbstractJavaObject type = null;

  /**
   * the initial value of the attribute.
   */
  private String initialValue = null;

  /**
   * wether this object must be mapped to the persistence API.
   */
  private boolean mappable = true;



  /**
   * returns the initial value of the attribute.
   * 
   * @return the initialValue
   * @see com.genia.toolbox.uml_generator.model.AttributeModel#getInitialValue()
   */
  public String getInitialValue()
  {
    return initialValue == null ? getType().getDefaultValue() : initialValue;
  }



  /**
   * set the new initial value of the attribute.
   * 
   * @param initialValue
   *          the initialValue to set
   * @see com.genia.toolbox.uml_generator.model.AttributeModel#setInitialValue(java.lang.String)
   */
  public void setInitialValue(final String initialValue)
  {
    if (initialValue != null && !initialValue.startsWith("new ") && type instanceof EnumerationModel) {
      this.initialValue = type.getQualifiedName() + "." + initialValue;
    }
    else {
      this.initialValue = initialValue;
    }
  }



  /**
   * getter for type property.
   * 
   * @return the type
   */
  public AbstractJavaObject getType()
  {
    return type;
  }



  /**
   * setter for type property.
   * 
   * @param type
   *          the type to set
   */
  public void setType(AbstractJavaObject type)
  {
    this.type = type;
  }



  /**
   * getter for the mappable property.
   * 
   * @return the mappable
   */
  public boolean isMappable()
  {
    return mappable;
  }



  /**
   * setter for the mappable property.
   * 
   * @param mappable
   *          the mappable to set
   */
  public void setMappable(boolean mappable)
  {
    this.mappable = mappable;
  }

}
